BufferedInputStream.read(byte[]) Causes problems. Anyone have this problem before?

Posted by K-RAN on Stack Overflow See other posts from Stack Overflow or by K-RAN
Published on 2011-01-06T00:51:47Z Indexed on 2011/01/06 0:53 UTC
Read the original article Hit count: 112

Filed under:
|
|

Hello! I've written a Java program that downloads audio files for me and I'm using BufferedInputStream. The read() function works fine but is really slow so I've tried using the overloaded version using byte[].

For some reason, the audio becomes lossy and strange after download. I'm not totally sure what I'm doing wrong so any help is appreciated! Here's the simplified, sloppy version of the code.

BufferedInputStream bin = new BufferedInputStream((new URL(url)).openConnection().getInputStream());
File file = new File(fileName);
FileOutputStream fop = new FileOutputStream(file);
int rd = bin.read();
while(rd != -1)
{
     fop.write(rd);
     rd = bin.read();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about file-io